package com.company.JUC;

import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.TimeUnit;

public class SynchronousQueueDemo {
    public static void main(String[] args) {
        SynchronousQueue<String> synchronousQueue = new SynchronousQueue<>();
        new Thread(()->{
            try {
                System.out.println("1111put");
                synchronousQueue.put("11");
                System.out.println("2222put");
                synchronousQueue.put("22");
                System.out.println("3333put");
                synchronousQueue.put("33");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        },"1111").start();
        new Thread(()->{
            try {
                TimeUnit.SECONDS.sleep(2);
                synchronousQueue.take();
                System.out.println(111);
                TimeUnit.SECONDS.sleep(2);
                synchronousQueue.take();
                System.out.println(222);
                TimeUnit.SECONDS.sleep(2);
                synchronousQueue.take();
                System.out.println(333);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }).start();
    }
}
